//
//  LCYRegisterViewController.m
//  EPA
//
//  Created by lanou3g on 16/4/26.
//  Copyright © 2016年 liu. All rights reserved.
//

#import "LCYRegisterViewController.h"
#import "LCYNetWorkRequestManager.h"
@interface LCYRegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *unameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation LCYRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark - 点击注册按钮
- (IBAction)didClickRegisterBtn:(UIButton *)sender {
    [LCYNetWorkRequestManager requestURL:[NSURL URLWithString:@"http://api2.pianke.me/user/reg"] RequestMethod:LCY_POST Params:@{@"email":self.emailTextField.text,@"gender":@"0",@"uname":self.unameTextField.text,@"passwd":self.passwordTextField.text} Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
//            NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
            NSMutableDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *dataDic = jsonDic[@"data"];
            NSString *msg = dataDic[@"msg"];
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:msg?msg:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
            [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self presentViewController:alertC animated:YES completion:nil];
            });
            
        }
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
